<template>
  <view class="home">
    <form-item :formJson="formJson" @handleSubmit="handleSubmit">
    </form-item>
    <back-page></back-page>
  </view>
</template>

<script setup>
  import {
    onMounted,
    ref
  } from 'vue';
  import formItem from '@/components/form-item/form-item.vue';
  import { houseOption, buy_house } from '../../../config/api';
  const formJson = ref([{
    label: '期望小区',
    key: 'xiaoqu',
    type: 'text',
    placeholder: "选择周边小区",
    border: true,
    required: true,
  }, {
    label: '选择户型',
    key: 'house_type',
    key_text: 'house_type_text',
    type: 'select',
    placeholder: "选择室卫厅",
    border: true,
    required: true,
    selectList: []
  }, {
    label: '楼层',
    key: 'floor',
    type: 'text',
    placeholder: "请输入楼层",
    border: true,
    required: true,
  }, {
    label: '期望房屋面积',
    key: 'space',
    type: 'text',
    placeholder: "请输入",
    border: true,
    required: true,
    suffix: '平米'
  }, {
    label: '联系人',
    key: 'real_name',
    type: 'text',
    required: true,
    border: true,
    placeholder: "请输入联系人",
    radio: true,
  }, {
    label: '联系电话',
    key: 'user_phone',
    type: 'text',
    border: true,
    required: true,
    placeholder: "请输入联系电话",
    maxlength: '11'

  }, ])
  onMounted(() => {
    _houseOption()
  })

  // 获取小区户型
  const _houseOption = () => {
    houseOption().then(res => {
      formJson.value[1].selectList = res.data.house_type
    })
  }
  // 我要买房
  const handleSubmit = (row) => {
    delete row.house_type_text
    buy_house(row).then(res => {
      uni.$u.toast(res.msg)
      setTimeout(() => {
        uni.navigateBack()
      }, 500)
    })
  }
</script>

<style lang="scss" scoped>
  .home {
    padding: 0 24rpx;
    padding-bottom: calc(200rpx + env(safe-area-inset-bottom));
    background: #fff;
    min-height: 100vh;
  }

  ::v-deep .u-form-item__body__left__content__label {
    font-size: 30rpx !important;
    font-weight: 500;
  }

  ::v-deep .u-form-item__body {
    padding: 35rpx 0 !important;
  }

  ::v-deep .u-form-item__body__left__content__required {
    left: auto !important;
    right: -12rpx;
  }
</style>